/**
 * @Author 天下无敌
 * @Date 
 * @AIDE AIDE+ 
 */
package com.ecs.core.screen;
import com.ecs.core.MainGame;
import com.badlogic.gdx.ScreenAdapter;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.utils.ScreenUtils;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.utils.viewport.FillViewport;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;

public class LoadScreen extends ScreenAdapter{

	private final MainGame game;
	private Stage stage;
	public LoadScreen(MainGame game)
	{
		this.game = game;
	}

	@Override
	public void show()
	{
		float w = Gdx.graphics.getWidth();
		float h = Gdx.graphics.getHeight();
		stage = new Stage(new FillViewport(w,h));
		Image background = new Image(new TextureRegionDrawable(new Texture(Gdx.files.internal("background.jpg"))));
		background.setSize(w,h);
		stage.addActor(background);
		Label.LabelStyle ls = new Label.LabelStyle();
		ls.font = new BitmapFont();
		ls.font.getRegion().getTexture().setFilter(Texture.TextureFilter.Linear,Texture.TextureFilter.Linear);
		ls.font.getData().setScale(3f);
		ls.fontColor = Color.BLACK;
		Label loadText = new Label("load...100",ls){
			@Override
			public void act(float a){
				setPosition((w / 2) - (getWidth() / 2),100);
				setText("load..." + (int)(game.assetManager.getProgress() * 100));
			}
		};
		stage.addActor(loadText);
	}
	
	
	@Override
	public void render(float delta)
	{
		ScreenUtils.clear(Color.BLACK);
		stage.act();
		stage.draw();
		if(game.assetManager.update()){
			game.setScreen(new GameScreen(game));
		}
	}

	@Override
	public void hide()
	{
		//dispose();
	}

	
	@Override
	public void dispose()
	{
		stage.dispose();
	}
	
	
}
